<template>
  <div>
    <div v-if="list.length >0">
      <div v-for="(item, index) in list" :key="index">
        <div class="item">
          <input type="checkbox" v-model="item.complete">
          {{ item.title }}
          <button class="del" @click="del(item,index)">删除</button>
        </div>
      </div>
    </div>
    <div v-else>
      暂无数据
    </div>
  </div>
</template>

<script>
import { computed, defineComponent } from 'vue'
import { useStore } from 'vuex'

export default defineComponent({
  name: 'NavMain',
  props: {
    list: {
      type: Array,
      required: true
    }
  },
  emits: ['del'],
  setup (props, ctx) {
    const store = useStore()
    const list1 = computed(() => {
      return store.state.list
    })
    console.log(list1)

    const del = (item, index) => {
      console.log(item)
      ctx.emit('del', index)
    }

    return {
      del,
      list1
    }
  }
})
</script>

<style scoped>
.item {
  height: 35px;
  line-height: 35px;
  position: relative;
  width: 160px;
  cursor: pointer;
}

.item:hover {
  background: #dddddd;
}

.item:hover button {
  display: block;
}

.item button {
  position: absolute;
  right: 6px;
  top: 6px;
  display: none;
  z-index: 99;
}
</style>
